package com.wdn.secondchapter;

import java.util.Arrays;

/**
 * 反转字符串
 * Created by wangxin on 2015/11/25.
 */
public class Reverse {
    public static void main(String[] args) {
        Reverse reverse = new Reverse();
        reverse.reverse1("abcdefghi");
    }
    void swap(char[] c){
        int start = 0;
        int end = c.length - 1;
        while (start<end){
            c[start] = (char)(c[start]^c[end]);
            c[end] = (char)(c[start]^c[end]);
            c[start] = (char)(c[start]^c[end]);
            start++;
            end--;
        }
        System.out.println(Arrays.toString(c));
    }
    public void reverse1(String s){
        if(s=="") return;
        char[] c = s.toCharArray();
        swap(c);
    }
}
